<template>
  <div class="login">
    <section class="form-container">
      <div class="manage-tip">
        <img class="login-logo" :src="Loginlogo" alt="" />
        <span class="title">TOY运营后台管理系统</span>
      </div>
      <el-form
        :model="loginUser"
        :rules="rules"
        ref="loginForm"
        class="loginForm"
      >
        <div class="items">
          <el-form-item label="" prop="username">
            <img :src="UserIcon" alt="" class="icon" />
            <el-input
              v-model="loginUser.username"
              placeholder="请输入邮箱"
              type="text"
            ></el-input>
          </el-form-item>
        </div>
        <div class="items">
          <el-form-item label="" prop="password">
            <img :src="PwdIcon" alt="" class="icon" />
            <el-input
              v-model="loginUser.password"
              placeholder="请输入密码"
              type="password"
            ></el-input>
          </el-form-item>
        </div>
        <el-form-item>
          <el-button @click="submitForm('loginForm')" class="submit-btn"
            >LOGIN</el-button
          >
        </el-form-item>
      </el-form>
    </section>
  </div>
</template>

<script>
import Loginlogo from "@/assets/image/login/login-logo.png";
import UserIcon from "@/assets/image/login/user.png";
import PwdIcon from "@/assets/image/login/pwd.png";
export default {
  name: "login",
  data() {
    return {
      Loginlogo,
      UserIcon,
      PwdIcon,
      loginUser: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          {
            required: true,
            message: "密码不能为空",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
          {
            min: 6,
            max: 30,
            message: "长度在 6 到 30 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$router.push("/index");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #2148c0;
  background-image: url(./../../assets/image/login/bg.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  .form-container {
    width: 400px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 5px;
    text-align: center;
    .manage-tip {
      text-align: center;
      .login-logo {
        margin: 0 auto 36px;
      }
      .title {
        font-weight: bold;
        font-size: 26px;
        color: #fff;
      }
    }
  }
  .loginForm {
    margin-top: 72px;
    border-radius: 5px;
    .el-form-item {
      position: relative;
      .icon {
        position: absolute;
        top: 14px;
        left: 26px;
        width: 36px;
        height: 36px;
      }
    }

    .el-input {
      height: 60px;
      border: 1px solid #fff;
      border-radius: 4px;
      box-sizing: border-box;
      padding-left: 80px;
    }
  }

  .submit-btn {
    width: 100%;
    height: 60px;
    margin-top: 40px;
  }
}
</style>
